/* $Header: pneu_sig.c,v 2.2 01/10/02 10:33:01 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1992                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:  pneu_sig.c                                            */
/* ============                                                        */
/*                                                                     */
/* Author:  rick                                                       */
/*          lesley: additions/changes                                  */
/*                                                                     */
/* MODULE PURPOSE:  provide signal scaling constants for pneumatics    */
/*                  and other signals requiring special handling       */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <zone_config.h>
#include <p_status.h>
#include <zone_status.h>
#include <status.h>
#include <error.h>
#include <sig_types.h>
#include <sig_ui.h>
#include <sigpath.h>
#include <p_ui.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

#define PRES_SIG_SCALE_FACTOR (SIG_SCALE_FACTOR)

/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

void SetPlotConstants( SIG_TYPE type, PLOT_CONSTANTS *values )
{

    INT32 value;
    pPLOT_CONSTANTS pconst;

    switch ( type )
    {
        case MON_15VNEG_SIGNAL:         pconst = (pPLOT_CONSTANTS)&MON_15VNEG_CONSTS;
                                        values->divisor = pconst->divisor;
                                        values->multiplier = pconst->multiplier;
                                        value = ConvertToMv(Mon_15Vpos_Rdg,(pPLOT_CONSTANTS)&MON_15VPOS_CONSTS);
                                        values->offset = pconst->offset * value/15000;
                                        break;

        case COL1_FLOW_SIGNAL:          values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetColumnFlowScale( pCOLUMN_1 );
                                        break;
        case COL2_FLOW_SIGNAL:          values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetColumnFlowScale( pCOLUMN_2 );
                                        break;
        case F_INLET_FLOW_SETPT_SIGNAL:
        case F_INLET_FLOW_SIGNAL:       values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetInletFlowScale( pFRONT_INLET );
                                        break;
        case B_INLET_FLOW_SETPT_SIGNAL:
        case B_INLET_FLOW_SIGNAL:       values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetInletFlowScale( pBACK_INLET );
                                        break;
        case F_D_GAS1_F_SETPT_SIGNAL:
        case F_DET_GAS1_FLOW_SIGNAL:    values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetDetFlowScale( pFRONT_DETECTOR, 1 );
                                        break;
        case F_D_GAS2_F_SETPT_SIGNAL:
        case F_DET_GAS2_FLOW_SIGNAL:    values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetDetFlowScale( pFRONT_DETECTOR, 2 );
                                        break;
        case F_D_GAS3_F_SETPT_SIGNAL:
        case F_DET_GAS3_FLOW_SIGNAL:    values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetDetFlowScale( pFRONT_DETECTOR, 3 );
                                        break;
        case B_D_GAS1_F_SETPT_SIGNAL:
        case B_DET_GAS1_FLOW_SIGNAL:    values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetDetFlowScale( pBACK_DETECTOR, 1 );
                                        break;
        case B_D_GAS2_F_SETPT_SIGNAL:
        case B_DET_GAS2_FLOW_SIGNAL:    values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetDetFlowScale( pBACK_DETECTOR, 2 );
                                        break;
        case B_D_GAS3_F_SETPT_SIGNAL:
        case B_DET_GAS3_FLOW_SIGNAL:    values->multiplier = SIG_SCALE_FACTOR;
                                        values->offset = 0;
                                        values->divisor = GetDetFlowScale( pBACK_DETECTOR, 3 );
                                        break;
        case COL1_PRES_SIGNAL:          values->multiplier = GetColumnPresScale( pCOLUMN_1 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case COL2_PRES_SIGNAL:          values->multiplier = GetColumnPresScale( pCOLUMN_2 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case F_INLET_PRES_SETPT_SIGNAL:
        case F_INLET_PRES_SIGNAL:       values->multiplier = GetInletPresScale( pFRONT_INLET )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case B_INLET_PRES_SETPT_SIGNAL:
        case B_INLET_PRES_SIGNAL:       values->multiplier = GetInletPresScale( pBACK_INLET )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case F_D_GAS1_P_SETPT_SIGNAL:
        case F_DET_GAS1_PRES_SIGNAL:    values->multiplier = GetDetPresScale( pFRONT_DETECTOR, 1 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case F_D_GAS2_P_SETPT_SIGNAL:
        case F_DET_GAS2_PRES_SIGNAL:    values->multiplier = GetDetPresScale( pFRONT_DETECTOR, 2 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case F_D_GAS3_P_SETPT_SIGNAL:
        case F_DET_GAS3_PRES_SIGNAL:    values->multiplier = GetDetPresScale( pFRONT_DETECTOR, 3 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case B_D_GAS1_P_SETPT_SIGNAL:
        case B_DET_GAS1_PRES_SIGNAL:    values->multiplier = GetDetPresScale( pBACK_DETECTOR, 1 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case B_D_GAS2_P_SETPT_SIGNAL:
        case B_DET_GAS2_PRES_SIGNAL:    values->multiplier = GetDetPresScale( pBACK_DETECTOR, 2 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case B_D_GAS3_P_SETPT_SIGNAL:
        case B_DET_GAS3_PRES_SIGNAL:    values->multiplier = GetDetPresScale( pBACK_DETECTOR, 3 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case AUX_3_PRES_SETPT_SIGNAL:
        case AUX_3_PRES_SIGNAL:         values->multiplier = GetAuxPresScale( pAUX_3 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case AUX_4_PRES_SETPT_SIGNAL:
        case AUX_4_PRES_SIGNAL:         values->multiplier = GetAuxPresScale( pAUX_4 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case AUX_5_PRES_SETPT_SIGNAL:
        case AUX_5_PRES_SIGNAL:         values->multiplier = GetAuxPresScale( pAUX_5 )
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;
        case ATM_PRES_SIGNAL:           values->multiplier = ATMOSPHERIC_PRES_SOURCE_SCALING
                                                             * PRES_SIG_SCALE_FACTOR
                                                             * PRES_UNITS_CONVERTION;
                                        values->offset = 0;
                                        values->divisor = GetPresUnitsConversion();
                                        break;

        default: ;
    }

}

/***********************************************************************/
/* FUNCTION:   SigPresUnitsChanged                                     */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: some of the sig plot constants need to change if pressure  */
/*          units are changed.  this routine informs sigpath that      */
/*          such an event has occurred so it can update plot consts.   */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/***********************************************************************/

void SigPresUnitsChanged( void )
{
   /* Reset the signal type without re-writing to the active workfile. */
   /* This will force any pressure signals to have the correct units.  */

   (void) SetSignalTypeMain( pSIGNAL1, (SIG_TYPE)GetSignalType( pSIGNAL1 ), FALSE );
   (void) SetSignalTypeMain( pSIGNAL2, (SIG_TYPE)GetSignalType( pSIGNAL2 ), FALSE );
   (void) SetSignalTypeMain( pSIGNALP, (SIG_TYPE)GetSignalType( pSIGNALP ), FALSE );
}

/***********************************************************************/
/* FUNCTION:   SigDetDiagLinearModeChanged                             */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: The uECD is linearized in the signal path firmware.  To    */
/*          disable it we will not execute the linearization if the    */
/*          det diag linear mode is set to ON.  We need to update      */
/*          the uECD flag in the signal table appropriately.           */
/*                                                                     */
/* RETURNED VALUE:  none                                               */
/*                                                                     */
/***********************************************************************/

void SigDetDiagLinearModeChanged( void )
{
   SigPresUnitsChanged();
}

